package com.webervser.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class ClientHandel1 {
    private Socket socket;
    private String Methon;
    private String uri;
    private String prclocl;
    Map<String,String>map= new HashMap<>();
   public ClientHandel1 (Socket socket) throws IOException {//构造器
       this.socket=socket;


       //请求消息行
       String line = readline();
       System.out.println(line);
       String[]arr = line.split("\\s");
       arr[0]=Methon;
       arr[1]=uri;
       arr[2]=prclocl;
       System.out.println(Methon);
       System.out.println(uri);
       System.out.println(prclocl);


       //解析消息头
       while (true){
           line=readline();
           if (line.isEmpty()) {
               break;
           }
          arr = line.split("\\s");
        map.put(arr[0],arr[1]);
       }
       System.out.println("header"+map);

   }

//从socket获取客户端发过来的信息
    public String readline() throws IOException {
        InputStream in = socket.getInputStream();
        char pre = 'a', ure = 'a';
        StringBuilder builder = new StringBuilder();
        int b;
        while ((b = in.read()) != -1) {
            ure = (char) b;
            if (pre == 13 && ure == 10) {
                break;
            }
            builder.append(ure);
            pre = ure;
        }
       return builder.toString().trim();
        //看到回车和换行就获取到第一行
    }
}
